/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2022-09-22
 * Time: 7:02
 */
public class Test1 {
    public static int findClosest(String[] words, String word1, String word2) {
        int l1 = -1;
        int l2 = -1;
        int l = 10000;
        for(int i = 0;i < words.length;i++){
            if(word1.equals(words[i])){
                l1 = i;
            }
            if(word2.equals(words[i])){
                l2 = i;
            }
            if(l1 != -1&& l2 != -1){
                l = Math.min(Math.abs(l1-l2),l);
            }
        }
        return l;
    }
    public static void main(String[] args) {
        String[] words={"I","am","a","student","from","a","university","in","a","city"};
        String  word1 = "a";
        String word2 = "student";
        System.out.println(findClosest(words, word1, word2));
    }
}
